package castledefense.logic.buildings;

import castledefense.data.BuildingData;
import castledefense.logic.Map;

public abstract class ElementBuilding extends Building {

	protected int[] upgradeLevel = { 0, 0, 0, 0 };

	public ElementBuilding(Map map, int posX, int posY, int size, int type) {
		super(map, posX, posY, size, type);
	}
	
	public int getUpgradeLevel(int type){
		if(type < 0 || type > 3){
			return 0;
		}else{
			return upgradeLevel[type];
		}
	}

	@Override
	public void upgrade(int newType) {

		int upCost = BuildingData.getUpgradeCost(newType, upgradeLevel[newType]);
		if (this.buildingType == BuildingData.tower2) {
			upCost *= 2;
		}
		if (BuildingData.money >= upCost) {
			if (elementType == -1) {
				elementType = newType;
				upgradeLevel[elementType]++;
				BuildingData.money -= upCost;
				cost += upCost;
			} else if (elementType == newType) {
				if (upgradeLevel[elementType] < BuildingData.maxUpgrades) {
					upgradeLevel[elementType]++;
					BuildingData.money -= upCost;
					cost += upCost;
				}
			}
		}
	}

	
}
